Skip to content

Conversation

@szy21
Copy link
Member

@szy21 szy21 commented Jan 22, 2026

Purpose

Removes grid-scale thermo state and uses new Thermodynamics API.

Removes ts and adds ᶜT, ᶜq_tot_safe, ᶜq_liq_rai, ᶜq_ice_sno to the cache. Also adds h_tot back to the cache because using @lazy results in gpu error. The difference between ᶜq_tot_safe and ᶜq_tot (a lazy broadcasting) is ᶜq_tot_safe is clipped to 0. The difference between ᶜq_liq_rai, ᶜq_liq and ᶜq_rai is ᶜq_liq_rai = ᶜq_liq + ᶜq_rai and clipped to 0. Same for ᶜq_ice_sno. I am open to different names. ᶜT, ᶜq_tot_safe, ᶜq_liq_rai, ᶜq_ice_sno essentially create the previous thermo state. Clipping the humidities to 0 recovers the previous behavior of thermo state.

I will remove subgrid thermo state and remaining TD.PhaseEquil in separate PRs.

To-do

Content


  • I have read and checked the items on the review checklist.

@szy21 szy21 added the do-not-merge-yet Block from bors label Jan 22, 2026
@szy21 szy21 force-pushed the zs/thermo_state branch 27 times, most recently from c98b81f to e95e753 Compare January 26, 2026 06:31
@szy21 szy21 marked this pull request as ready for review January 26, 2026 06:31
@szy21 szy21 changed the title remove thermo state remove grid-scale thermo state Jan 26, 2026
@szy21 szy21 requested review from costachris and tapios January 26, 2026 06:38
@szy21 szy21 force-pushed the zs/thermo_state branch 2 times, most recently from 4dfb4ea to 934de93 Compare January 26, 2026 07:23
@szy21 szy21 added Breaking 💥 and removed do-not-merge-yet Block from bors labels Jan 26, 2026
@szy21
Copy link
Member Author

szy21 commented Jan 26, 2026

Copy link
Member

@tapios tapios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Amazing work, and huge lift. Thank you!


# Saturation state at current thermodynamic state (via θ, p, q_tot)
ts_current = TD.PhaseEquil_pθq(thermo_params, p_c, θli, q_tot)
q_sat = TD.q_vap_saturation(thermo_params, ts_current)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be more straightforward to pass in temperature rather than pressure, and then compute q_sat and other quantities we need from that. Wouldn't that avoid use of PhaseEquil... here? (Same for the other cloud_fraction function above.)

Perhaps your intention was to do that, or something like it, in a separate PR, and that's fine too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I want to remove the PhaseEquil in the next PR, partially because I didn't know how to deal with this field of named tuple. But now I think I know:)

end

function saturation_distance(q_tot, q_sat, ᶜts, θli, thermo_params, Δθli_fd)
function saturation_distance(q_tot, q_sat, p_c, θli, thermo_params, Δθli_fd)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above: I think this gets easier to change, and to reduce reliance on equilibrium constructors, by passing in temperature rather than pressure.

@. ᶜts = ts_gs(thermo_args..., Y.c, ᶜK, ᶜΦ, Y.c.ρ)
@. ᶜp = TD.air_pressure(thermo_params, ᶜts)
# Compute thermodynamic state variables using individual getter functions.
# Note: For EquilMoistModel, this calls saturation_adjustment 3 times per grid point
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above: why not combining getters so that we call SA only once?

@szy21 szy21 force-pushed the zs/thermo_state branch 6 times, most recently from fdd4b9a to 86cce9c Compare January 27, 2026 07:02
@szy21 szy21 enabled auto-merge January 27, 2026 07:03
@szy21 szy21 added this pull request to the merge queue Jan 27, 2026
Any commits made after this event will not be merged.
Merged via the queue into main with commit 71f8f86 Jan 27, 2026
40 of 43 checks passed
@szy21 szy21 deleted the zs/thermo_state branch January 27, 2026 08:55
@szy21 szy21 mentioned this pull request Jan 28, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants